package org.dfl.core.data.connectors;

import org.dfl.core.data.types.CollectionType;
import org.dfl.core.data.types.Type;
import org.dfl.core.data.types.TypeContainer;
import org.dfl.core.data.types.TypeManager;


/**
 * Type connector to connect collection types
 * @author Piotr Wlodarczyk
 *
 */
public class CollectionTypeConnector extends SimpleTypeConnector {
	
	/**
	 * Create a connector
	 * @param source - any type container
	 * @param target - target type container with a type Collection
	 */
	public CollectionTypeConnector(TypeContainer source, TypeContainer target) {
		super(source, target);
	}

	@Override
	public TypeContainer getTarget() {
		Type targetType = super.getTarget().getType();
		if(TypeManager.isAnyType(targetType)){
			targetType.merge(TypeManager.getCollectionType());
		}
		// tu juz MUSI BYC kolekcja
		return ((CollectionType) super.getTarget().getType()).getSubtypeContainer();
	}
}
